package com.right.health.app.ui.me.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.magic.basic.adapter.BaseAbsAdapter;
import com.right.health.app.R;
import com.right.health.app.bean.DrugReminderInfo;

/*
 * Created by hopeliao on 2019-09-24
 *
 */
public class DrugReminderAdapter extends BaseAbsAdapter<DrugReminderInfo> {

    private View.OnClickListener mClickListener;

    public void setOnClickListener(View.OnClickListener listener) {
        this.mClickListener = listener;
    }

    public DrugReminderAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.drug_reminder_item, null);
            viewHolder = new ViewHolder();

            viewHolder.nameTv = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.timeTv = (TextView) convertView.findViewById(R.id.tv_time);
            viewHolder.cycleTv = (TextView) convertView.findViewById(R.id.tv_cycle);

            viewHolder.notTakeMedicine = convertView.findViewById(R.id.rl_not_take_medicine);
            viewHolder.takeMedicine = convertView.findViewById(R.id.rl_take_medicine);

            if(mClickListener != null) {
                viewHolder.notTakeMedicine.setOnClickListener(mClickListener);
                viewHolder.takeMedicine.setOnClickListener(mClickListener);
            }
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        DrugReminderInfo info = mDataSource.get(position);

        viewHolder.nameTv.setText(info.remindname);

        viewHolder.cycleTv.setText(String.format("1天%s次", info.times));
        viewHolder.timeTv.setText(info.time);

        if ("0".equals(info.iseat)) { //未服用
            viewHolder.notTakeMedicine.setVisibility(View.VISIBLE);
            viewHolder.takeMedicine.setVisibility(View.GONE);
        } else {
            viewHolder.notTakeMedicine.setVisibility(View.GONE);
            viewHolder.takeMedicine.setVisibility(View.VISIBLE);
        }

        viewHolder.takeMedicine.setTag(position);
        viewHolder.notTakeMedicine.setTag(position);
        return convertView;
    }

    private class ViewHolder {
        private ImageView contentImage;
        private TextView nameTv, timeTv;
        private TextView cycleTv;
        private View notTakeMedicine, takeMedicine;
    }
}
